package com.docker.jy.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.docker.chy.domain.DoctorPatient;
import com.docker.chy.mapper.DoctorPatientMapper;
import com.docker.jy.mapper.DoctorStorageManagementMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.docker.common.annotation.Log;
import com.docker.common.core.controller.BaseController;
import com.docker.common.core.domain.AjaxResult;
import com.docker.common.enums.BusinessType;
import com.docker.jy.domain.DoctorStorageManagement;
import com.docker.jy.service.IDoctorStorageManagementService;
import com.docker.common.utils.poi.ExcelUtil;
import com.docker.common.core.page.TableDataInfo;

/**
 * 会员储值管理Controller
 * 
 * @author ruoyi
 * @date 2025-04-11
 */
@RestController
@RequestMapping("/jy/vipstorageManagement")
public class DoctorStorageManagementController extends BaseController
{
    @Autowired
    private IDoctorStorageManagementService doctorStorageManagementService;
    @Autowired
    private DoctorPatientMapper doctorPatientMapper;

    /**
     * 查询会员储值管理列表
     */
    @PreAuthorize("@ss.hasPermi('jy:vipstorageManagement:list')")
    @GetMapping("/list")
    public TableDataInfo list(DoctorStorageManagement doctorStorageManagement)
    {
        startPage();
        List<DoctorStorageManagement> list = doctorStorageManagementService.selectDoctorStorageManagementList(doctorStorageManagement);
        //通过patient_id一对一查询患者信息
        for (DoctorStorageManagement doctorStorageManagement1 : list) {
            DoctorPatient doctorPatient = doctorPatientMapper.selectDoctorPatientById(Long.valueOf(doctorStorageManagement1.getPatientId()));
            doctorStorageManagement1.setDoctorPatient(doctorPatient);
        }
        return getDataTable(list);
    }

    /**
     * 导出会员储值管理列表
     */
    @PreAuthorize("@ss.hasPermi('jy:vipstorageManagement:export')")
    @Log(title = "会员储值管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DoctorStorageManagement doctorStorageManagement)
    {
        List<DoctorStorageManagement> list = doctorStorageManagementService.selectDoctorStorageManagementList(doctorStorageManagement);
        ExcelUtil<DoctorStorageManagement> util = new ExcelUtil<DoctorStorageManagement>(DoctorStorageManagement.class);
        util.exportExcel(response, list, "会员储值管理数据");
    }

    /**
     * 获取会员储值管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('jy:vipstorageManagement:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(doctorStorageManagementService.selectDoctorStorageManagementById(id));
    }

    /**
     * 新增会员储值管理
     */
    @PreAuthorize("@ss.hasPermi('jy:vipstorageManagement:add')")
    @Log(title = "会员储值管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DoctorStorageManagement doctorStorageManagement)
    {
        return toAjax(doctorStorageManagementService.insertDoctorStorageManagement(doctorStorageManagement));
    }

    /**
     * 修改会员储值管理
     */
    @PreAuthorize("@ss.hasPermi('jy:vipstorageManagement:edit')")
    @Log(title = "会员储值管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DoctorStorageManagement doctorStorageManagement)
    {
        return toAjax(doctorStorageManagementService.updateDoctorStorageManagement(doctorStorageManagement));
    }

    /**
     * 删除会员储值管理
     */
    @PreAuthorize("@ss.hasPermi('jy:vipstorageManagement:remove')")
    @Log(title = "会员储值管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(doctorStorageManagementService.deleteDoctorStorageManagementByIds(ids));
    }
}
